import SwiftUI

struct EANScannerPage: View {
    @Environment(\.dismiss) private var dismiss
    
    @StateObject private var scanner = EANScanner()
    
    @Binding var lastEANCode: String
    
    var body: some View {
        ZStack {
            EANScannerView(scanner: scanner)
        }
        .onChange(of: scanner.lastEANCode){
            if scanner.lastEANCode != "" {
                lastEANCode = scanner.lastEANCode
                dismiss()
            }
        }
        .navigationTitle("扫描书籍条形码")
        .navigationBarTitleDisplayMode(.inline)
    }
}

#Preview {
    EANScannerPage(lastEANCode: .constant(""))
}
